home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18034 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: sizeof() question >>> :)
  5. Date: Thu, 18 Apr 1996 16:16:01 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4l5pqj$c8m@news.halcyon.com>
  8. References: <1996Apr12.061927@topaz> <31714828.1574068@news.linex.com> <4l0dcr$14t0@darwin.nbnet.nb.ca> <danpop.829678939@news.cern.ch> <4l4fik$1a8_005@donstarr.best.com>
  9. NNTP-Posting-Host: blv-pm3-ip12.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. super@donstarr.org (Don Starr) wrote:
  13.  
  14. >In article <danpop.829678939@news.cern.ch>,
  15. >   danpop@mail.cern.ch (Dan Pop) wrote:
  16. >*>
  17. >*> If you allocate the space for the array you can call one of the memory
  18. >*> routines which return the size of the allocation.
  19. >*> Dave Gaudet via Rick Bruce
  20. >*
  21. >*There is no such "routine" in the C language.
  22. >*
  23. >*Dan
  24.  
  25. >Technically, there is no such _any_ routine in the C language. The language 
  26. >doesn't define any functions - "standard" libraries do.
  27.  
  28. >As to the original question, if you know how your heap is structured (from 
  29. >the source to your malloc(), new, or whatever), you can get the size of any 
  30. >allocation from it.
  31.  
  32. >Don
  33.  
  34.     You can?  Post some code.  
  35.     Even when there's some support behind it, e.g. the GlobalSize()
  36. function in MS Windows, the size returned may be padded larger than
  37. the amount you've requested.  You can guess how big the memory is
  38. you're using.  
  39.     BTW, some memory management routines add on extra bytes, even beyond
  40. the padding, to track allocations, detect overwrites, etc.  and these
  41. fields would also enter into your hypothetical allocated_sizeof(), but
  42. maybe only if _DEBUG is defined.   However, you don't dare overwite
  43. these fields.
  44.     I think the wisest advise is to track the size yourself when you
  45. allocate, pass array dims yourself to functions, etc.
  46.                     --Norm 
  47.  
  48.